Using Minified Page Specific JS [migrated]

Posted by Mike C on Pro Webmasters See other posts from Pro Webmasters or by Mike C
Published on 2012-07-09T18:45:25Z Indexed on 2012/07/09 21:23 UTC
Read the original article Hit count: 206

Filed under:
|
|

I've been working on a rather large scale project which makes use of a number of different pages with some very specific Javascript for each of them. To lessen load times, I plan to minify it all in to one file before deploying.

The problem is this: how should I avoid launching page specific JS on pages which don't require it? So far my best solution has been to wrap each page in some additional container

<div id='some_page'>
...everything else...
</div>

and I extended jQuery so I can do something like this:

// If this element exists when the DOM is ready, execute the function
$('#some_page').ready(function() {
    ...
});

Which, while kind of cool, just rubs me the wrong way.

© Pro Webmasters or respective owner

Related posts about JavaScript

Related posts about jQuery